package de.hdu.pms.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import de.hdu.pms.model.Projekte;

public class ProjekteDao extends HibernateDaoSupport{

public static Logger Log = Logger.getLogger(ProjekteDao.class);
public static void setLog(Logger log){
	Log = log;
}


/**
 * Finds the Project by Id (Primary Key)
 * and returns it
 * @param mit_id
 * @return den Mitarbeiter
 * @author BBV
 */

public Projekte findById(int id){
	HibernateTemplate template = getHibernateTemplate();
	return (Projekte) template.get(Projekte.class, id);
}


/**
 * Saves the project to DB and returns the saved project
 * @author BBV
 * @param projekte
 * @return
 */

public Projekte save(Projekte projekte){
	HibernateTemplate template = getHibernateTemplate();
	template.saveOrUpdate(projekte);
	return projekte;
}



/**
 * Lists all projects in the db
 * @return results
 * @author BBV
 */

@SuppressWarnings("unchecked")
public List<Projekte> findAll(){
	HibernateTemplate template = getHibernateTemplate();
	@SuppressWarnings("rawtypes")
	List results = template.loadAll(Projekte.class);
	return results;
}


/**
 * deletes a project from the db
 * @param projekte
 * @author BBV
 * @return void 
 */

public void delete(Projekte projekte){
	HibernateTemplate template = getHibernateTemplate();
	template.delete(projekte);
}

/**
 * Lists all active projects
 * @return results
 * @author BBV
 */

public List<Projekte> findActive(){
	HibernateTemplate template = getHibernateTemplate();
	@SuppressWarnings("unchecked")
	List<Projekte> results = template.find("from Projekte p where p.projekt_aktiv = 1");
	return results;
}



}